package com.htx.zqs.blesmartmask.db;

import com.htx.zqs.blesmartmask.MyApplication;

/**
 * Created by KomoriWu
 * on 2019/3/30.
 * 每一个BeanManager都管理着数据库中的一个表，我将这些管理者在ManagerFactory中进行统一管理
 */


public class ManagerFactory {
    BeforeCourseManager beforeCourseManager;
    AfterCourseManager afterCourseManager;

    private static ManagerFactory mInstance = null;
        public static ManagerFactory getInstance() {
            if (mInstance == null) {
                synchronized (ManagerFactory.class) {
                    if (mInstance == null) {
                        mInstance = new ManagerFactory();
                    }
                }
            }
            return mInstance;
        }

    public synchronized BeforeCourseManager getBeforeCourseManager() {
            if (beforeCourseManager == null){
                beforeCourseManager = new BeforeCourseManager(DaoManager.getInstance(
                        MyApplication.appContext).getDaoSession().getBeforeCourseDataDao());
            }
        return beforeCourseManager;
    }

    public synchronized AfterCourseManager getAfterCourseManager(){
            if (afterCourseManager == null){
                afterCourseManager = new AfterCourseManager(DaoManager.getInstance(
                        MyApplication.appContext).getDaoSession().getAfterCourseDataDao());
            }
            return afterCourseManager;
    }
}
